<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Biaya_model extends CI_Model{
	function __construct() {
		parent::__construct();
	}
	
	function get_biaya($no_spj){
		$query = $this->db->get_where('TblBiaya',array('NoSPJ'=>$no_spj));
		if($query->num_rows()>0){
			return $query->result_array();
		}else{
			return FALSE;
		}
	}
	
	function get_biaya_lain($date=''){
		if ($date == '') {
			$date = date('Ymd');
		} else {
			$date = $this->date_func->change_format_date($date, 'd-m-Y', 'Ymd');
		}
		$this->db->select('TbReservasi.NoSPJ');
		$this->db->select('TbReservasi.NoPol');
		$this->db->select('TbReservasi.Driver');
		$this->db->select('TblBiaya.id');
		$this->db->select('TblBiaya.nama_coa');
		$this->db->select('TblBiaya.jumlah');
		$this->db->select('TblBiaya.cabang');
		$this->db->select('TblBiaya.idkasir');
		$this->db->distinct();
		$this->db->from('TblBiaya');
		$this->db->join('TbReservasi','TblBiaya.NoSPJ=TbReservasi.NoSPJ','inner');
		$this->db->where('TblBiaya.tgl_pembayaran',$date);
		return $this->db->get()->result_array();
	}
        
        function get_biaya_lain_for_kasir($kota,$date=''){
		if ($date == '') {
			$date = date('Ymd');
		} else {
			$date = $this->date_func->change_format_date($date, 'd-m-Y', 'Ymd');
		}
		$this->db->select('TbReservasi.NoSPJ');
		$this->db->select('TbReservasi.NoPol');
		$this->db->select('TbReservasi.Driver');
		$this->db->select('TblBiaya.id');
		$this->db->select('TblBiaya.nama_coa');
		$this->db->select('TblBiaya.jumlah');
		$this->db->select('TblBiaya.cabang');
		$this->db->select('TblBiaya.idkasir');
		$this->db->distinct();
		$this->db->from('TblBiaya');
                $this->db->where('TblBiaya.tgl_pembayaran = "'.$date.'" AND (Asal = "'.$kota.'" OR Tujuan = "'.$kota.'")');
		$this->db->join('TbReservasi','TblBiaya.NoSPJ=TbReservasi.NoSPJ','inner');
		return $this->db->get()->result_array();
	}
	
	function get_no_spj_per_day($date=''){
		if ($date == '') {
			$date = date('Ymd');
		} else {
			$date = $this->date_func->change_format_date($date, 'd-m-Y', 'Ymd');
		}
		$this->db->distinct();
		return $this->db->get_where('TbReservasi',array('TGLSPJ'=>$date))->result_array();
	}
        
        function get_no_spj_per_day_for_kasir($kota,$date=''){
		if ($date == '') {
			$date = date('Ymd');
		} else {
			$date = $this->date_func->change_format_date($date, 'd-m-Y', 'Ymd');
		}
		$this->db->distinct();
//                $this->db->select('NoSPJ');
//		$this->db->select('NoPol');
//		$this->db->select('Driver');
//		$this->db->select('JamBerangkat');
//		$this->db->select('Asal');
//		$this->db->select('Tujuan');
                $this->db->where('TGLSPJ = "'.$date.'" AND (Asal = "'.$kota.'" OR Tujuan = "'.$kota.'")');
		return $this->db->get('TbReservasi')->result_array();
	}
	
	function insert_data($data){
		$this->db->insert('TblBiaya',$data);
	}
	
	function get_data_cetak($id){
		$this->db->select('TbReservasi.NoSPJ');
		$this->db->select('TbReservasi.NoPol');
		$this->db->select('TbReservasi.Driver');
		$this->db->select('TbReservasi.Asal');
		$this->db->select('TbReservasi.Tujuan');
		$this->db->select('TblBiaya.nama_coa');
		$this->db->select('TblBiaya.jumlah');
		$this->db->select('TblBiaya.cabang');
		$this->db->select('TblBiaya.idkasir');
		$this->db->distinct();
		$this->db->from('TblBiaya');
		$this->db->join('TbReservasi','TblBiaya.NoSPJ=TbReservasi.NoSPJ');
		$this->db->where('TblBiaya.id',$id);
		return $this->db->get()->row_array();
	}
}